﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using nplJobsCommon.JobSeeker;
using nplJobs.DB;
using System.Data;
using nplJobsCommon.Job;
using System.Data.SqlClient;


namespace nplJobsDAL.Select
{
    public class SelectJobAlertFrequency : DataAccessBase
    {
        public int JobAlertFrequencyID { get; set; }
        public Guid JobseekerID { get; set; }

        public SelectJobAlertFrequency()
        {
            StoredProcedureName = StoredProcedure.Name.spSelectJobAlertFrequency.ToString();
        }

        #region GetJobAlertFrequency
        public List<JobAlertFrequency> GetJobAlertFrequency()
        {
            DataBaseHelper dbHelper;
            DataSet dsJobAlertFrequency;

            try
            {
                SelectJoAlertFrequencyParameters selectJobSeekerParameters = new SelectJoAlertFrequencyParameters(this.JobAlertFrequencyID);
                dbHelper = new DataBaseHelper(StoredProcedureName);
                dbHelper.Parameters = selectJobSeekerParameters.Parameters;
                dsJobAlertFrequency = dbHelper.Run(base.ConnectionString, dbHelper.Parameters);
                return GetList(dsJobAlertFrequency);
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

        #region SQL parameters for selecting job alert frequency 
        public class SelectJoAlertFrequencyParameters
        {
            private SqlParameter[] _parameters;

            public SelectJoAlertFrequencyParameters(int frequencyID)
            {
                this.FrequencyID = frequencyID;
                Build();
            }
            private void Build()
            {
                SqlParameter[] parameters = 
                {
                    new SqlParameter("@FrequencyID", FrequencyID),
                };

                Parameters = parameters;
            }

            public int FrequencyID { get; set; }

            public SqlParameter[] Parameters
            {
                get { return _parameters; }
                set { _parameters = value; }
            }
        }
        #endregion
        #region GetList
        private List<JobAlertFrequency> GetList(DataSet dsJobAlertFrequency)
        {
            List<JobAlertFrequency> jobAlertFrequency;
            try
            {
                jobAlertFrequency = (from d in dsJobAlertFrequency.Tables[0].AsEnumerable()
                                 select new JobAlertFrequency
                              {
                                  ID = d.Field<int>("ID"),
                                  Frequency = d.Field<string>("Frequency")
                              }).ToList();

                return jobAlertFrequency;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally { }
        }
        #endregion

    }
    
}
